home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
elv18src.zip
/
curses.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-10
|
24KB
|
1,122 lines
/* curses.c */
/* Author:
* Steve Kirkendall
* 14407 SW Teal Blvd. #C
* Beaverton, OR 97005
* kirkenda@cs.pdx.edu
*/
/* This file contains the functions & variables needed for a tiny subset of
* curses. The principle advantage of this version of curses is its
* extreme speed. Disadvantages are potentially larger code, few supported
* functions, limited compatibility with full curses, and only stdscr.
*/
#include "config.h"
#include "vi.h"
#if ANY_UNIX || OS2
# if UNIXV || COH_386 || OS2
# if TERMIOS
# ifdef AIX
# define _XOPEN_SOURCE
# define _ALL_SOURCE
# endif
# include <termios.h>
# ifdef AIX
# undef _XOPEN_SOURCE
# undef _ALL_SOURCE
# endif
# else
# include <termio.h>
# endif
# if !OS2
# ifndef NO_S5WINSIZE
# ifdef NEED_PTEM
# include <sys/stream.h> /* winsize struct defined in one of these? */
# include <sys/ptem.h>
# endif
# else
# undef TIOCGWINSZ /* we can't handle it correctly yet */
# endif
# endif
# else
# if TERMIOS
# include <termios.h>
# else
# ifdef hpux
# include <termio.h>
# else
# include <sgtty.h>
# endif
# endif
# endif
#endif
#if TOS
# include <osbind.h>
#endif
#if OSK
# include <sgstat.h>
#endif
#if VMS
extern int VMS_read_raw; /* Set in initscr() */
#endif
static void starttcap P_((char *));
/* variables, publicly available & used in the macros */
char *termtype; /* name of terminal entry */
short ospeed; /* speed of the tty, eg B2400 */
#if OSK
char PC_; /* Pad char */
char *BC; /* backspace character string */
#else
char PC; /* Pad char */
#endif
WINDOW *stdscr; /* pointer into kbuf[] */
WINDOW kbuf[KBSIZ]; /* a very large output buffer */
int LINES; /* :li#: number of rows */
int COLS; /* :co#: number of columns */
int AM; /* :am: boolean: auto margins? */
int PT; /* :pt: boolean: physical tabs? */
char *VB; /* :vb=: visible bell */
char *UP; /* :up=: move cursor up */
char *SO = ""; /* :so=: standout start */
char *SE = ""; /* :se=: standout end */
char *US = ""; /* :us=: underline start */
char *UE = ""; /* :ue=: underline end */
char *MD = ""; /* :md=: bold start */
char *ME = ""; /* :me=: bold end */
char *AS = ""; /* :as=: alternate (italic) start */
char *AE = ""; /* :ae=: alternate (italic) end */
#ifndef NO_VISIBLE
char *MV; /* :mv=: "visible" selection start */
#endif
char *CM; /* :cm=: cursor movement */
char *CE; /* :ce=: clear to end of line */
char *CD; /* :cd=: clear to end of screen */
char *AL; /* :al=: add a line */
char *DL; /* :dl=: delete a line */
#if OSK
char *SR_; /* :sr=: scroll reverse */
#else
char *SR; /* :sr=: scroll reverse */
#endif
char *KS = ""; /* :ks=: switch keypad to application mode */
char *KE = ""; /* :ke=: switch keypad to system mode */
char *KU; /* :ku=: key sequence sent by up arrow */
char *KD; /* :kd=: key sequence sent by down arrow */
char *KL; /* :kl=: key sequence sent by left arrow */
char *KR; /* :kr=: key sequence sent by right arrow */
char *HM; /* :HM=: key sequence sent by the <Home> key */
char *EN; /* :EN=: key sequence sent by the <End> key */
char *PU; /* :PU=: key sequence sent by the <PgUp> key */
char *PD; /* :PD=: key sequence sent by the <PgDn> key */
char *KI; /* :kI=: key sequence sent by the <Insert> key */
char *kD; /* :kD=: key sequence sent by the <Delete> key */
#ifndef NO_FKEY
char *FKEY[NFKEYS]; /* :k0=: ... :k9=: sequences sent by function keys */
#endif
char *IM = ""; /* :im=: insert mode start */
char *IC = ""; /* :ic=: insert the following character */
char *EI = ""; /* :ei=: insert mode end */
char *DC; /* :dc=: delete a character */
char *TI = ""; /* :ti=: terminal init */ /* GB */
char *TE = ""; /* :te=: terminal exit */ /* GB */
#ifndef NO_CURSORSHAPE
#if 1
char *CQ = (char *)0;/* :cQ=: normal cursor */
char *CX = (char *)1;/* :cX=: cursor used for EX command/entry */
char *CV = (char *)2;/* :cV=: cursor used for VI command mode */
char *CI = (char *)3;/* :cI=: cursor used for VI input mode */
char *CR = (char *)4;/* :cR=: cursor used for VI replace mode */
#else
char *CQ = ""; /* :cQ=: normal cursor */
char *CX = ""; /* :cX=: cursor used for EX command/entry */
char *CV = ""; /* :cV=: cursor used for VI command mode */
char *CI = ""; /* :cI=: cursor used for VI input mode */
char *CR = ""; /* :cR=: cursor used for VI replace mode */
#endif
#endif
char *aend = ""; /* end an attribute -- either UE or ME */
char ERASEKEY; /* backspace key taken from ioctl structure */
#ifndef NO_COLOR
char normalcolor[24];
char SOcolor[24];
char SEcolor[24];
char UScolor[24];
char UEcolor[24];
char MDcolor[24];
char MEcolor[24];
char AScolor[24];
char AEcolor[24];
char Qcolor[24];
# ifndef NO_POPUP
char POPUPcolor[24];
# endif
# ifndef NO_VISIBLE
char VISIBLEcolor[24];
# endif
#endif
#if ANY_UNIX || OS2
# if UNIXV || COH_386 || hpux || OS2
# if TERMIOS
static struct termios oldtermio; /* original tty mode */
static struct termios newtermio; /* cbreak/noecho tty mode */
# else
static struct termio oldtermio; /* original tty mode */
static struct termio newtermio; /* cbreak/noecho tty mode */
# endif
# else
static struct sgttyb oldsgttyb; /* original tty mode */
static struct sgttyb newsgttyb; /* cbreak/nl/noecho tty mode */
static int oldint; /* ^C or DEL, the "intr" character */
# ifdef TIOCSLTC
static int oldswitch; /* ^Z, the "suspend" character */
static int olddswitch; /* ^Y, the "delayed suspend" char */
static int oldquote; /* ^V, the "quote next char" char */
# endif
# endif
#endif
#if OSK
static struct sgbuf oldsgttyb; /* orginal tty mode */
static struct sgbuf newsgttyb; /* noecho tty mode */
#endif
/* This boolean variable indicated whether the termcap description is
* sufficient to support visual mode.
*/
int canvi = TRUE; /* boolean: know enough for visual mode? */
static char *capbuf; /* capability string buffer */
/* Initialize the Curses package. */
void initscr()
{
/* create stdscr */
stdscr = kbuf;
/* make sure TERM variable is set */
termtype = getenv("TERM");
#if OS2
/* get initial video state; turn on ANSI */
v_vio_init();
#endif
#if VMS
/* VMS getenv() handles TERM as a environment setting. Foreign
* terminal support can be implemented by setting the ELVIS_TERM
* logical or symbol to match a tinytcap entry.
*/
if (!strcmp(termtype,"unknown"))
termtype = getenv("ELVIS_TERM");
#endif
#if MSDOS
/* For MS-DOS, if TERM is unset we can default to "pcbios", or
* maybe "rainbow".
*/
if (!termtype)
{
#ifdef RAINBOW
if (*(unsigned char far*)(0xffff000eL) == 6 /* Rainbow 100a */
|| *(unsigned char far*)(0xffff000eL) == 148)/* Rainbow 100b */
{
termtype = "rainbow";
}
else
#endif
termtype = "pcbios";
}
if (!strcmp(termtype, "pcbios"))
#else
if (!termtype)
#endif
{
#if ANY_UNIX || OSK
termtype = "unknown";
starttcap(termtype);
#endif
#if AMIGA
termtype = TERMTYPE;
starttcap(termtype);
#endif
#if MSDOS
starttcap("pcbios");
#endif
#if OS2
termtype = "ansi";
starttcap(termtype);
#endif
#if TOS
termtype = "vt52";
starttcap(termtype);
#endif
#if VMS
write(2, "UNKNOWN terminal: define ELVIS_TERM\n", (unsigned)36);
exit(2);
#endif
}
else
{
#if MSDOS
*o_pcbios = 0;
#endif
/* start termcap stuff */
starttcap(termtype);
}
/* change the terminal mode to cbreak/noecho */
#if ANY_UNIX || OS2
# if UNIXV || COH_386 || hpux || OS2
# if TERMIOS
tcgetattr(2, &oldtermio);
# else
ioctl(2, TCGETA, &oldtermio);
# endif
# else
ioctl(2, TIOCGETP, &oldsgttyb);
# endif
#endif
#if OSK
_gs_opt(0, &oldsgttyb);
#endif
#if VMS
VMS_read_raw = 1; /* cbreak/noecho */
vms_open_tty();
#endif
resume_curses(TRUE);
}
/* Shut down the Curses package. */
void endwin()
{
/* change the terminal mode back the way it was */
suspend_curses();
#if AMIGA
amiclosewin();
#endif
#if OS2
v_vio_restore(); /* restore initial video state */
#endif
}
static int curses_active = FALSE;
extern int oldcurs;
/* Send any required termination strings. Turn off "raw" mode. */
void suspend_curses()
{
#if ANY_UNIX && !(UNIXV || COH_386 || hpux)
struct tchars tbuf;
# ifdef TIOCSLTC
struct ltchars ltbuf;
# endif
#endif
#ifndef NO_CURSORSHAPE
if (has_CQ)
{
do_